home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Misc / CmdKey.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-17  |  3.5 KB  |  201 lines  |  [TEXT/KAHL]

  1. /*
  2.     CmdKey - DA to test whether cmd-key equivalents for Edit menu get
  3.     passed twice to DA's.  (This seemed to happen in older versions of
  4.     TransSkel.  Build this DA, install it, then run it while a TransSkel
  5.     program is running.
  6.  
  7.     (Only relevant on pre-MultiFinder systems without WaitNextEvent().)
  8.     
  9.     Paul DuBois
  10.     Wisconsin Regional Primate Research Center
  11.     1220 Capitol Court
  12.     University of Wisconsin-Madison
  13.     Madison, WI  53715-1299  USA
  14.     
  15.     dubois@primate.wisc.edu
  16.  
  17.     01/31/89 Created.
  18.     10/26/93 Updated for THINK C 6.0.1.
  19. */
  20.  
  21.  
  22. # define    bufSiz        512
  23.  
  24.  
  25. typedef enum    /*  menu item numbers  */
  26. {
  27.     quit = 1
  28. };
  29.  
  30.  
  31. /*  global variables  */
  32.  
  33. Boolean        isOpen = false;        /* true if DA already open */
  34. WindowPtr    theWind;
  35. DCtlPtr        dce;
  36. short        dCtlRefNum;
  37.  
  38.  
  39. /*
  40.     Redraw the window.  It is assumed that the port is set correctly.
  41.     The ValidRect is done because sometimes this is called before any
  42.     update event is obtained.  The ValidRect cancels any that might be
  43.     pending, preventing two redraws.
  44. */
  45.  
  46. Update ()
  47. {
  48.     ValidRect (&theWind->portRect);
  49. }
  50.  
  51.  
  52. DrawNum (c)
  53. char    c;
  54. {
  55. static short    h = 10;
  56. static short    v = 12;
  57.  
  58.     MoveTo (h, v);
  59.     DrawChar (c);
  60.     if ((h += 10) > 120)
  61.     {
  62.         h = 10;
  63.         v += 12;
  64.     }
  65. }
  66.  
  67.  
  68. int
  69. main(p, d, n)
  70. cntrlParam    *p;    /*  ==> parameter block  */
  71. DCtlPtr        d;    /*  ==> device control entry  */
  72. short        n;    /*  entry point selector  */
  73. {
  74. Point            thePt;
  75. Rect            r;
  76. EventRecord        *theEvent;
  77.  
  78.     dCtlRefNum = (dce = d)->dCtlRefNum;
  79.  
  80.     /*  check to make sure data area was allocated  */
  81.         
  82.     if (d->dCtlStorage == 0)
  83.     {
  84.         if (n == 0)                        /*  open  */
  85.             CloseDriver(dCtlRefNum);
  86.     }
  87.     else switch (n)    /*  dispatch  */
  88.     {
  89.  
  90.     case 0:        /*  open  */
  91.  
  92.         /*
  93.             Need to set these values each time, because the OS resets
  94.             them before every call...
  95.         */
  96.  
  97.         d->dCtlFlags |= dNeedLock | dNeedTime | dNeedGoodBye;
  98.         d->dCtlDelay = 0;
  99.         d->dCtlEMask = updateEvt | activateEvt | mouseDown
  100.                     | keyDown | autoKey ;
  101.  
  102. /*
  103.     Check to see whether already open or not.  If not, set up window,
  104.     window growing limits, etc.  The SelectWindow is for the case where
  105.     the DA is already open but hidden behind some other window.
  106.     Selecting CmdKey from the DA menu when already open simply has the
  107.     effect of bringing it to the front.
  108. */
  109.     
  110.         if (!isOpen)
  111.         {
  112.             isOpen = true;
  113.  
  114.             SetRect (&r, 25, 80, 490, 320);
  115.             theWind = NewWindow (nil, &r, "\pCmdKey", true,
  116.                                     noGrowDocProc, (WindowPtr) -1L, true, 0L);
  117.             ((WindowPeek) theWind)->windowKind = dCtlRefNum;
  118.             SetPort (theWind);
  119.             TextFont (monaco);
  120.             TextSize (9);
  121.         }
  122.  
  123.         SelectWindow (theWind);
  124.  
  125.         break;
  126.  
  127.     case 2:        /*  control  */
  128.  
  129.         SetPort (theWind);
  130.         switch (p->csCode)
  131.         {
  132.  
  133.         case accEvent:    /* need glasses for next statement */
  134.  
  135.             theEvent = (EventRecord *) * (long *) &p->csParam;
  136.             switch (theEvent->what)
  137.             {
  138.  
  139.             case activateEvt:
  140.                 SysBeep (2);
  141.                 break;
  142.             
  143.             case updateEvt:
  144.             
  145.                 BeginUpdate (theWind);
  146.                 Update ();
  147.                 EndUpdate (theWind);
  148.                 break;
  149.  
  150.             case mouseDown:
  151.                 SysBeep (2);
  152.                 break;
  153.                 
  154.             case autoKey:
  155.             case keyDown:
  156.                     DrawNum ('X');
  157.                     if (theEvent->modifiers & cmdKey)
  158.                     {
  159.                     short    i = theEvent->message & charCodeMask;
  160.                     
  161.                         do {
  162.                             DrawNum ((i%10) + '0');
  163.                             i /= 10;
  164.                         }
  165.                         while (i != 0);
  166.                     }
  167.             }
  168.             break;
  169.  
  170.         case accUndo:
  171.             DrawNum ('0');
  172.             break;
  173.         case accCut:
  174.             DrawNum ('2');
  175.             break;
  176.         case accCopy:
  177.             DrawNum ('3');
  178.             break;
  179.         case accPaste:
  180.             DrawNum ('4');
  181.             break;
  182.         case accClear:
  183.             DrawNum ('5');
  184.             break;
  185.  
  186.         /*case goodBye:
  187.             break;*/
  188.  
  189.         }
  190.         break;
  191.  
  192.     case 4:        /*  close  */
  193.         DisposeWindow (theWind);    /* get rid of window and controls */
  194.         break;
  195.     }
  196.     
  197.     /*  done  */
  198.     
  199.     return (0);
  200. }
  201.